var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
 var theRequest = new Object();
 var name_id ='';
 var fn=0;
 if (url.indexOf('?') != -1) {
	 var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
	 var strs = str.split('&');
		 for (var i = 0; i < strs.length; i++) {
		    theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
		 }
		 name_id=theRequest.name_id; //此时的theRequest就是我们需要的参数；
		 console.log(name_id)
 }
 var height = document.body.clientHeight
 $(".matchList").css("height",height-20);
 $(function(){
	 $.ajax({
		 url:'../matchController/getMatchList',
		 data:{
			 "nameId":name_id,
			 "fn":0
		 },
		 success:function(data){
			 console.log(data)
			 if(data==null || data=="" ||data.length==0){
				 $(".matchList").html("<div><img src='../image/none.jpg' style='width: 300px;height:300px;margin-left: 225px;margin-top:100px;'></div>");
			 }else{
				 fn=fn+20;
				 $(".matchList").html("");
				 $.each(data,function(idex,item){
				 		debugger
						var startDate = new Date(item.start_time).format("hh:mm");
						var remark='';
						var sign_person=0;
						if(item.sign_person==null || item.sign_person=="" || item.sign_person=="undefined"){
							sign_person=0
						}else{
							sign_person=item.sign_person
						}
						if(item.remark==null || item.remark=="" || item.remark=="undefined"){
							remark="无";
						}else{
							remark=item.remark
						}
						
						if(sign_person==item.max_person){
							$(".matchList").append("<div class='box'><div class='gamePicBox'><img class='gamePic' src='"+item.matchListpic+"'></div><div class='gameContentBox'><div class='gameTitle'>"+item.name+"</div><div class='gameRank'><div class='area'>段位："+item.lowest_rank+"-"+item.highest_rank+"</div><div class='area'>"+item.region+"</div></div><div class='gameReward'>奖励："+remark+"</div></div><div class='gameSignUp'><div class='person' style='background: #E22635;height: 40px;line-height: 40px;width: 80px;border-radius: 10px;'>已 满</div><div class='beginTime'>"+startDate+"开赛</div></div></div>");
						}else{
							$(".matchList").append("<a href='../html/matchContent.html?id="+item.id+"'><div class='box'><div class='gamePicBox'><img class='gamePic' src='"+item.matchListpic+"'></div><div class='gameContentBox'><div class='gameTitle'>"+item.name+"</div><div class='gameRank'><div class='area'>段位："+item.lowest_rank+"-"+item.highest_rank+"</div><div class='area'>"+item.region+"</div></div><div class='gameReward'>奖励："+remark+"</div></div><div class='gameSignUp'><div class='person'>已报<label class='endperson'>"+sign_person+"/"+item.max_person+"</label>人</div><div class='beginTime'>"+startDate+"开赛</div></div></div></a>");
						}
					 })
			 }
			 
		 },
		 error:function(){
			 alert("加载失败");
		 }
	 })
 });
 
 const scrollDom = document.getElementById('matchList');

 scrollDom.onscroll = () => {
	if (scrollDom.clientHeight + parseInt(scrollDom.scrollTop) === scrollDom.scrollHeight) {
		 $.ajax({
			 url:'../matchController/getMatchList',
			 data:{
				 "nameId":name_id,
				 "fn":fn
			 },
			 success:function(data){
				 console.log(data)
					 fn=fn+20;
				 $.each(data,function(idex,item){
					 var startDate = new Date(item.start_time).format("hh:mm");
						var remark='';
						var sign_person=0;
						if(item.sign_person==null || item.sign_person=="" || item.sign_person=="undefined"){
							sign_person=0
						}else{
							sign_person=item.sign_person
						}
						if(item.remark==null || item.remark=="" || item.remark=="undefined"){
							remark="无";
						}else{
							remark=item.remark
						}
						
						if(sign_person==item.max_person){
							$(".matchList").append("<div class='box'><div class='gamePicBox'><img class='gamePic' src='"+item.matchListpic+"'></div><div class='gameContentBox'><div class='gameTitle'>"+item.name+"</div><div class='gameRank'><div class='area'>段位："+item.lowest_rank+"-"+item.highest_rank+"</div><div class='area'>"+item.region+"</div></div><div class='gameReward'>奖励："+remark+"</div></div><div class='gameSignUp'><div class='person' style='background: #E22635;height: 40px;line-height: 40px;width: 80px;border-radius: 10px;'>已 满</div><div class='beginTime'>"+startDate+"开赛</div></div></div>");
						}else{
							$(".matchList").append("<a href='../html/matchContent.html?id="+item.id+"'><div class='box'><div class='gamePicBox'><img class='gamePic' src='"+item.matchListpic+"'></div><div class='gameContentBox'><div class='gameTitle'>"+item.name+"</div><div class='gameRank'><div class='area'>段位："+item.lowest_rank+"-"+item.highest_rank+"</div><div class='area'>"+item.region+"</div></div><div class='gameReward'>奖励："+remark+"</div></div><div class='gameSignUp'><div class='person'>已报<label class='endperson'>"+sign_person+"/"+item.max_person+"</label>人</div><div class='beginTime'>"+startDate+"开赛</div></div></div></a>");
						}
					 })
			 },
			 error:function(){
				 alert("加载失败");
			 }
		 })
	  }
}
	  
